<?php 

namespace app\admin\controller;
use app\admin\controller\Base;
use app\admin\model\twitter;
use think\Request;
class Twitters extends Base{
	//判断是否是POST请求
	public function ispost(){
		if (!Request::instance()->isPost()){
			$this->redirect('index');
		}
	}
	public function index(){
		$twitter = new twitter;
		$twitter = $twitter->select();
		return $this->fetch('admin/twitter',['twitter'=>$twitter]);
	}
	public function twadd(){
		$this->ispost();
		$twitter = new twitter;
		$twitter->content = input('content');
		$twitter->time = time();
		if ($twitter->save()) {
			$data = ["result"=>1, "msg"=>"发布成功"];
			echo json_encode($data);
		}else{
			$data = ["result"=>2, "msg"=>"发布失败"];
			echo json_encode($data);
		}
	}
	public function twdel(){
		$this->isPost();
		$id = input('id');
		$twitter = twitter::get($id);
		if($twitter->delete()){
			$data = ["result"=>1, "msg"=>"删除成功"];
			echo json_encode($data);
		}else{
			$data = ["result"=>2, "msg"=>"删除失败"];
			echo json_encode($data);
		}
	}
}




 ?>